<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>单图上传预览</title>
  <style>
    .preview {
      width: 200px;
      height:200px;
    }
    .preview img {
      width: 100%;
    }
  </style>
</head>
<body>
  <div class="container">
    <input type="file" accept="image/*" onchange="uploadImg(event,this)">
    <div class="preview">

    </div>
  </div>
  <script>
    var URL = window.URL || window.webkitURL || window.mozURL
    function uploadImg(e,dom) {
      var e = event || e
      var fileObj =
          dom instanceof HTMLElement
            ? dom.files[0]
            : $(dom)[0].files[0]
      console.log(e)
      console.log(dom)
      var container = document.querySelector('.preview')
      var img = new Image()
      img.src = URL.createObjectURL(fileObj)
      img.onload = function() {
        container.appendChild(img)
      }

    }
  </script>
</body>
</html>